package edu.pku.sei.transformation.editor.actions;

import org.eclipse.jface.action.Action;

import edu.pku.sei.transformation.editor.model.goal.Description;
import edu.pku.sei.transformation.editor.model.goal.TransformationGoal;
import edu.pku.sei.transformation.editor.views.dialogs.GoalDescriptionDialog;
import edu.pku.sei.transformation.editor.views.icons.IconsProvider;

public class OpenDescriptionAction extends Action {
	private Description description;
	private boolean isGoalDescription = false;
	
	public OpenDescriptionAction(Description description) {
		this.description = description;
		this.setText(description.toString());
		this.setImageDescriptor(IconsProvider.getImageDescriptor(IconsProvider.EXPRESSION_ICO));
	}
	public OpenDescriptionAction(Description description, boolean isGoalDescription) {
		this.description = description;
		this.setText(description.toString());
		this.isGoalDescription = isGoalDescription;
		this.setImageDescriptor(IconsProvider.getImageDescriptor(IconsProvider.EXPRESSION_ICO));
	}
	@Override
	public void run() {
		GoalDescriptionDialog d = new GoalDescriptionDialog();
		d.setDeleteable(!isGoalDescription);
		d.setSummaryChangeable(!isGoalDescription);
		d.setTitle("description");
		d.setDescription(description);
		int result = d.open();
		if (result == GoalDescriptionDialog.DELETE) {
			if (description.getContainer() instanceof TransformationGoal) {
				((TransformationGoal)description.getContainer()).getEndDescription().remove(description);
			}
		} 
	}
}
